﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using YasharEl.Infrastructure.ObjectFactory;

namespace YasharEl.Infrastructure.ServiceBus.Unicast
{
    /// <summary>
    /// The default dispatch factory
    /// </summary>
    public class DefaultDispatcherFactory : IMessageDispatcherFactory
    {
        public IEnumerable<Action> GetDispatcher(Type messageHandlerType, IDependencyResolver resolver, object toHandle)
        {
            yield return () => HandlerInvocationCache.Invoke(resolver.Resolve(messageHandlerType), toHandle);
        }

        public bool CanDispatch(Type handler)
        {
            return true;
        }
    }
}
